package com.xpu.shardingjdbc.algorithm;

import com.google.common.collect.Range;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

public class DbRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
        //获取逻辑表
        String logicTableName = rangeShardingValue.getLogicTableName();
        System.out.println(logicTableName);
        //获取分片名称字段
        String columnName = rangeShardingValue.getColumnName();
        System.out.println(columnName);
        Range<Long> valueRange = rangeShardingValue.getValueRange();
        if(valueRange.hasUpperBound()){
            Long aLong = valueRange.upperEndpoint();
            System.out.println(aLong);
        }
        if(valueRange.hasLowerBound()){
            Long lowerEndpoint = valueRange.lowerEndpoint();
            System.out.println(lowerEndpoint);
        }
        return Arrays.asList("ds1","ds2");
    }
}
